
const Carousel = require('../model/carousel.model')

class carouselService {
  async getCarousel(params){
    const json = await Carousel.findAll()
    return json
  }
  //分页查询轮播图
  async searchCarousel(params){
    let obj = Object.assign({},params)
    delete obj.pageNo
    delete obj.pageSize
    const { count, rows } = await Carousel.findAndCountAll(
      {
        limit:params.pageSize,
        offset:(params.pageNo -1) * params.pageSize,
        where:{...obj} 
      },
    )
    return {
      rows,
      count
    }
  }
  //新增轮播图
  async insertCarousel(params){
    const res = await Carousel.create(params)
    return res
  }
  //修改轮播图
  async updateCarousel(params){
    const res = await Carousel.update(
      {...params},
      { where:{id:params.id} }
    )
    return res
  }
  //删除轮播图
  async deleteOne(params){
    const res = await Carousel.destroy({ where:{ id:params.id } })
    return res
  }
  //查询一条信息
  async getOne(params){
    const res = await Carousel.findOne({
      where:{ id:params.id }
    })
    return res
  }
}

module.exports = new carouselService()